﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DispatchAssist.Weather.Helper;

namespace DispatchAssist.Weather
{
    /// <summary>
    /// 设置
    /// </summary>
    internal partial class frmWeatherSetting : Form
    {
        public frmWeatherSetting()
        {
            InitializeComponent();
        }

        private void plColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = this.plColor.BackColor;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.plColor.BackColor = colorDialog1.Color;
            }
        }

        private void btnSumbit_Click(object sender, EventArgs e)
        {
            Properties.UserSettings.Default.AirportColor = this.plColor.BackColor;
            Properties.UserSettings.Default.DefaultProvider = this.cbMapProvider.SelectedValue as Guid? ?? Guid.Empty;
            Properties.UserSettings.Default.IsShowAirport = cbShowAirport.Checked;
            Properties.UserSettings.Default.Save();

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void frmWeatherSetting_Load(object sender, EventArgs e)
        {
            this.cbMapProvider.DisplayMember = "Name";
            this.cbMapProvider.ValueMember = "WeatherProvideID";
            this.cbMapProvider.DataSource = ProviderHelper.GetAllWeatherProvider();

            if (this.cbMapProvider.Items.Count > 0)
            {
                this.cbMapProvider.SelectedValue = Properties.UserSettings.Default.DefaultProvider;
                if (this.cbMapProvider.SelectedValue == null)
                {
                    this.cbMapProvider.SelectedIndex = 0;
                }
            }


            this.plColor.BackColor = Properties.UserSettings.Default.AirportColor;
            this.cbShowAirport.Checked = Properties.UserSettings.Default.IsShowAirport;
        }
    }
}
